package cn.iocoder.yudao.module.design.controller.admin.problemdealerrel;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.design.controller.admin.problemdealerrel.vo.*;
import cn.iocoder.yudao.module.design.convert.problemdealerrel.ProblemDealerRelConvert;
import cn.iocoder.yudao.module.design.dal.dataobject.problemdealerrel.ProblemDealerRelDO;
import cn.iocoder.yudao.module.design.service.problemdealerrel.ProblemDealerRelService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Collection;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 问题处理人关联")
@RestController
@RequestMapping("/design/problem-dealer-rel")
@Validated
public class ProblemDealerRelController {

    @Resource
    private ProblemDealerRelService problemDealerRelService;

    @PostMapping("/create")
    @Operation(summary = "创建问题处理人关联")
    @PreAuthorize("@ss.hasPermission('design:problem-dealer-rel:create')")
    public CommonResult<Long> createProblemDealerRel(@Valid @RequestBody ProblemDealerRelCreateReqVO createReqVO) {
        return success(problemDealerRelService.createProblemDealerRel(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新问题处理人关联")
    @PreAuthorize("@ss.hasPermission('design:problem-dealer-rel:update')")
    public CommonResult<Boolean> updateProblemDealerRel(@Valid @RequestBody ProblemDealerRelUpdateReqVO updateReqVO) {
        problemDealerRelService.updateProblemDealerRel(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除问题处理人关联")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('design:problem-dealer-rel:delete')")
    public CommonResult<Boolean> deleteProblemDealerRel(@RequestParam("id") Long id) {
        problemDealerRelService.deleteProblemDealerRel(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得问题处理人关联")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('design:problem-dealer-rel:query')")
    public CommonResult<ProblemDealerRelRespVO> getProblemDealerRel(@RequestParam("id") Long id) {
        ProblemDealerRelDO problemDealerRel = problemDealerRelService.getProblemDealerRel(id);
        return success(ProblemDealerRelConvert.INSTANCE.convert(problemDealerRel));
    }

    @GetMapping("/list")
    @Operation(summary = "获得问题处理人关联列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('design:problem-dealer-rel:query')")
    public CommonResult<List<ProblemDealerRelRespVO>> getProblemDealerRelList(@RequestParam("ids") Collection<Long> ids) {
        List<ProblemDealerRelDO> list = problemDealerRelService.getProblemDealerRelList(ids);
        return success(ProblemDealerRelConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得问题处理人关联分页")
    @PreAuthorize("@ss.hasPermission('design:problem-dealer-rel:query')")
    public CommonResult<PageResult<ProblemDealerRelRespVO>> getProblemDealerRelPage(@Valid ProblemDealerRelPageReqVO pageVO) {
        PageResult<ProblemDealerRelDO> pageResult = problemDealerRelService.getProblemDealerRelPage(pageVO);
        return success(ProblemDealerRelConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出问题处理人关联 Excel")
    @PreAuthorize("@ss.hasPermission('design:problem-dealer-rel:export')")
   
    public void exportProblemDealerRelExcel(@Valid ProblemDealerRelExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<ProblemDealerRelDO> list = problemDealerRelService.getProblemDealerRelList(exportReqVO);
        // 导出 Excel
        List<ProblemDealerRelExcelVO> datas = ProblemDealerRelConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "问题处理人关联.xls", "数据", ProblemDealerRelExcelVO.class, datas);
    }




}
